package com.aqie.easy.hash;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 884 两句话中不常见单词
 */
public class UncommonFromSentences {
    public static String[] uncommonFromSentences(String A, String B) {
        HashMap<String, Integer> mapA = new HashMap<>();
        HashMap<String, Integer> mapB = new HashMap<>();
        String[] arrA = A.split("\\s");
        String[] arrB = B.split("\\s");
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < arrA.length; i++){
            mapA.put(arrA[i], mapA.getOrDefault(arrA[i],0) + 1);
        }

        for (int i = 0; i < arrB.length; i++){
            mapB.put(arrB[i], mapB.getOrDefault(arrB[i],0) + 1);
        }
        for (String key : mapA.keySet()){
            if (mapA.get(key) == 1 && !mapB.containsKey(key)){
                list.add(key);
            }
        }

        for(String key : mapB.keySet()){
            if (mapB.get(key) == 1 && !mapA.containsKey(key)){
                list.add(key);
            }
        }

        return list.toArray(new String[0]);

    }

    public static void main(String[] args) {

    }
}
